Component({
  data: {
    current: null,
    devices: [],
  },
  lifetimes: {
    created() {
      // 获取当前设备
      let current = wx.getStorageSync('currentDev');
      // 获取历史设备列表 
      let devices = wx.getStorageSync('devices') || [];

      // devices = [{
      //   RSSI: -62,
      //   advertisData: {},
      //   connectable: true,
      //   deviceId: "17F7DFDA-4DBF-4CAD-A11C-B630F786E1FF",
      //   localName: "YM_BB2400113139",
      //   name: "YM_BB2400113139",
      // },{
      //   deviceId: "17F7DFDA-4DBF-4CAD-A11C-B630F786E1F1",
      //   connectable: true,
      //   RSSI: -62,
      //   advertisData: {},
      //   localName: "YM_BB2400113138",
      //   name: "YM_BB2400113138",
      // },];
      current = 'YM_BB2400113139';
      this.setData({
        current,
        devices
      });
      console.log(current, devices);
    },
  },
  methods: {
    openHandleChange(e){
      let {item} = e.currentTarget.dataset;
      item.status = e.detail.value;
      if(!e.detail.value){
        this.setData({
          current:null,
        })
        wx.setStorage('current',null);
      }else{
        this.setData({
          current:item.localName,
        })
        wx.setStorage('current',item.localName);
      }
      this.triggerEvent('changeBluetooth',item);
    },
    onLeftFn() {
      this.triggerEvent('profileSetFn');
    },
  },
});